package com.jinzheng.qhwocket.commont;
import com.jinzheng.qhwocket.util.ResultObject;
import com.jinzheng.qhwocket.exception.ErrorException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 统一异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler  {

    @ExceptionHandler(ErrorException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    ResultObject handleException(ErrorException err){
        return ResultObject.createInstance(false,err.getMessage(),err.getErrorCode());
    }
}